<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>dPHP - Coding Standards</title>
<style type="text/css">
BODY {
    font-family: arial,helvetica,clean,sans-serif;
    font-size: 14px;    
}
TD, TH {
    font-size: 14px;
}
HR {
    width: 75%;
}
TABLE.block {
    padding: 4px;
    width: 50%;
}
TABLE.note {
    border: solid 1px #204a87;
    background-color: #729fcf;
    color: #000000;
}
TABLE.must {
    border: solid 1px #c4a000;
    background-color: #fce94f;
    color: #000000;
}
TABLE.should {
    border: solid 1px #4e9a06;
    background-color: #8ae234;
    color: #000000;
}
TABLE.code {
    font-family: monospace;
}
TABLE.example {
    border: solid 1px #babdb6;
    background-color: #eeeeec;
    color: #000000;
}
</style>
</head>
<body>
<a name="top"></a>
<center>
    <h1>dPHP - Coding Standards</h1>
</center>
<table align="center" cellpadding="4" cellspacing="0" border="0">
<tr>
    <td><i>$Revision: 83 $</i></td>
</tr>
<tr>
    <td><i>$Date: 2008-02-12 15:19:35 +0000 (Tue, 12 Feb 2008) $</i></td>
</tr>
</table>
<h2>Table of Contents</h2>
<ol>
    <li><a href="#intro">Introduction</a>
    <li><a href="#general">General Standards</a>
        <ol>
            <li><a href="#indent">Indentation and Line Length</a>
            <li><a href="#php_tags">PHP Code Tags</a>
            <li><a href="#encoding">File Format and Encoding</a>
        </ol>
    </li>    
    <li><a href="#naming">Naming Conventions</a>
    	<ol>
    		<li><a>Classes</a>
    		<li><a>Files and Directories</a>
    		<li><a>Functions and Methods</a>
    		<li><a>Constants</a>
    	</ol>
    <li><a>Control Structures</a>        
    <li><a>Comments</a>
        <ol>
            <li><a>phpDocumentor</a>
            <li><a>File Header Comment Blocks</a>
            <li><a>Comments for Functions</a>
            <li><a>Comments for Class</a>            
            <li><a>Comments for Class Members, Constants and Methods</a>
        </ol>
    </li>
    
</ol>
<hr>

<a name="intro"></a>
<h2>Introduction</h2>
<p>The dPHP Coding Standards (or CS for short) apply to code that is part of the
official dPHP packages. The aim of dPHP Coding Standards is to to keep the code
consistent, readable and easy to maintain by dPHP development group.</p>
<p align="center"><a href="#top">Top</a></p>
<hr>

<!--########## General Standards ##########-->
<a name="general"></a>
<h2>General Standards</h2>
<a name="indent"></a>
<h3>Indentation and Line Length</h3>
<table class="must block">
<tr>
    <td>
        <table border="0" cellpadding="4" cellspacing="0">
        <tr>
            <td valign="top"><img border="0" alt="Warning" src="images/icon_warning.gif"></td>
            <td valign="top">
                Use an indent of <b>4</b> spaces, do <b>not</b> use tabs to avoid
                viewing problem with different text editors. 
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>
<p>If you use Emacs, set <code>indent-tabs-mode</code> to <code>nil</code>.
Here is an example mode hook that will set up Emacs:</p>
<table align="center" class="code example block">
<tr>
    <td>
<pre>(defun php-mode-hook ()
    (setq tab-width 4
        c-basic-offset 4
        c-hanging-comment-ender-p nil
        indent-tabs-mode
    (not
        (and (string-match "/\\(PEAR\\|pear\\)/" (buffer-file-name))
            (string-match "\.php$" (buffer-file-name))))))</pre>
    </td>
</tr>
</table>
<p>Here are Vim rules for setting tabs:</p>
<table align="center" class="code example block">
<tr>
    <td>
<pre>set expandtab
set shiftwidth=4
set softtabstop=4
set tabstop=4</pre>
    </td>
</tr>
</table>
<br>
<table class="should block">
<tr>
    <td>
        <table border="0" cellpadding="4" cellspacing="0">
        <tr>
            <td valign="top"><img border="0" alt="Information" src="images/icon_information.gif"></td>
            <td valign="top">
                Lines are recommended to be kept at <b>80</b> characters long; and should not
                exceed <b>100</b> characters. 
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>
<p>Try your best to keep lines under 100 characters long for readability.</p>

<a name="php_tags"></a>
<h3>PHP Code Tags</h3>
<table class="must block">
<tr>
    <td>
        <table border="0" cellpadding="4" cellspacing="0">
        <tr>
            <td valign="top"><img border="0" alt="Warning" src="images/icon_warning.gif"></td>
            <td valign="top">
                <b>Always</b> use long PHP open tag (i.e. <code>&lt;?php</code>);
                do not use the short one (i.e. <code>&lt;?</code> or <code>&lt;?=</code>). 
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>
<p>Short PHP open tags are not portable as many hosting services do not enable it. So avoid
it for best portability.</p>

<a name="encoding"></a>
<h3>File Format and Encoding</h3>
<table class="must block">
<tr>
    <td>
        <table border="0" cellpadding="4" cellspacing="0">
        <tr>
            <td valign="top"><img border="0" alt="Warning" src="images/icon_warning.gif"></td>
            <td valign="top">
                Use <b>UTF-8</b> as character encoding for all text files (PHP source code,
                XML, text-based configuration files, etc).
                <br>
                <i>Remember to remove the BOM from files!</i>
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>
<p>UTF-8 is the de facto standard encoding for interchange of Unicode text. It is
also supported and used by most recent systems. All text files within dPHP project
must use UTF-8 as character encoding.</p>

<table class="should block">
<tr>
    <td>
        <table border="0" cellpadding="4" cellspacing="0">
        <tr>
            <td valign="top"><img border="0" alt="Information" src="images/icon_information.gif"></td>
            <td valign="top">
                Use *NIX-style line delimiter: lines should end only with a line feed (LF)
                character (decimal 10, hex 0A or \n in PHP).
                <br>
                <b>Do not use Macintosh-style line delimiter (lines ends only with a
                carriage return - CR).</b>
                <br><br>
                If file ends with a closing tag (<code>?></code>), there should be
                one line feed after the tag. It means right after the <code>></code>
                character is the LF character.                
            </td>
        </tr>
        </table>
    </td>
</tr>
</table>
<p>Windows-style line delimiter (CRLR) is also acceptable, but discouraged!</p>
<p>When file ends with a PHP closing tag (<code>?></code>), there must be <i>no
output</i>, even spaces and tabs, after the closing tag except for <i>at
most</i> one new-line delimiter (LF or CRLF).</p>

<p align="center"><a href="#top">Top</a></p>
<hr>
<!--########## General Standards ##########-->

<!--########## Naming Conventions ##########-->
<a name="naming"></a>
<!--########## Naming Conventions ##########-->

</body>
</html>